package initial;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import utility.IdDict;
import utility.Int2long;

/**
 * Rearrange data ID according "activeUsers.txt"
 * @author D
 * 
 */

public class Rearrange {
	
	private static IdDict dict = new IdDict();
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String dictPath = "/home/ddxu/data/activeUsers2.txt";
		dict.loadDict(dictPath);

		String dataPath = "/home/ddxu/data/edges4activeUsers.txt";
		String resultPath = "/home/ddxu/data/newEdges4activeUsers2.txt";
		
		String str;
		String[] tokens;
		int[] users;
		
		try {
			BufferedReader in = new BufferedReader(new FileReader(dataPath));
			BufferedWriter out = new BufferedWriter(new FileWriter(resultPath));
			while((str = in.readLine()) != null) {
				tokens = str.split("\t");
				users = Int2long.long2ints(Long.parseLong(tokens[0]));
				
				if((dict.dictValue(users[0]) != null) && (dict.dictValue(users[1]) != null)) {
					out.write(dict.dictValue(users[0]).toString());
					out.write("\t");
					out.write(dict.dictValue(users[1]).toString());
					out.write("\t");
					out.write(tokens[1]);
					out.newLine();
				}
			}
			in.close();
			out.flush();
			out.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
